//
//  MCXinZhiDuViewController.m
//  TLYL
//
//  Created by cai miao on 2018/1/8.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCXinZhiDuViewController.h"
#import "MCTopSelectedView.h"
#import "UIColor+MCColor.h"
#import "UIImage+Extension.h"
#import "MCTCReportSubModel.h"
#import <MJRefresh/MJRefresh.h>
#import "MCRefreshNormalHeader.h"
#import "MCMMIputView.h"
#import "MCXinZhiDuPopView.h"
#import "DatePickerView.h"
#import "MCNaviButton.h"
#import "MCRecordTool.h"
#import "MCXinZhiDuTableViewCell.h"
#import "MCXinZhiDuReportListModel.h"
#import "MCXinZhiDuReportTotalModel.h"
#import "MCXinZhiDuReportLotteryModel.h"
#import "MCXinZhiDuTableViewCell.h"
#import "MCBreadcrumbTrailView.h"

@interface MCXinZhiDuViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
/**下部滑动根view*/
@property (nonatomic,weak) MCTopSelectedView *topSelectedView;
@property (nonatomic,weak) UIScrollView *baseScrollView;
@property (nonatomic,weak) UIButton *lastBtn;
@property (nonatomic,weak) UIView *topBtnView;
@property (nonatomic,weak) UIView *botView;
@property (nonatomic,weak) UITableView *tableView;
@property (nonatomic,weak) UITableView *tableViewself;
@property (nonatomic,weak) UITableView *tableViewAll;
@property (nonatomic,assign) int CurrentPageIndex;
@property (nonatomic,assign) int IsSelf;
@property (nonatomic,assign) int isShow;
@property (nonatomic,assign) int LotteryId;
@property (nonatomic,strong) NSDate *beginDate;
@property (nonatomic,assign) BOOL isShowPopView;
@property (nonatomic,assign) int UserID;



///**条件选择*/
@property (nonatomic,weak) MCMMIputView *viewPop;
///**筛选框*/
@property (nonatomic,  weak) MCXinZhiDuPopView *popView;
/**数据源tableViewDataArray*/
@property (nonatomic,strong) NSMutableArray *tableViewDataArray;
/**数据源tableViewDataArray*/
@property (nonatomic,strong) NSMutableArray *tableViewSelfDataArray;


/**数据源tableViewDataArray*/
@property (nonatomic,strong) NSMutableArray *catergyDataArray;

/**数据源tableViewDataArray*/
@property (nonatomic,strong) NSMutableArray *tableViewAllDataArray;
/**datePicker 日期选择器*/
@property (nonatomic,  weak) DatePickerView  *datePicker;
/**datePicker 日期选择器*/
@property (nonatomic,  weak) UIButton  *btn;
@property (nonatomic,strong) MCXinZhiDuReportListModel *listModel;
@property (nonatomic,strong) MCXinZhiDuReportListModel *listSelfModel;
@property (nonatomic,strong) MCXinZhiDuReportTotalModel *totalModel;
@property (nonatomic,strong) MCXinZhiDuReportLotteryModel *lotteryModel;
@property (nonatomic,strong) MCBreadcrumbTrailView *trailView;
@property (nonatomic,strong) NSMutableArray *cengJiModelArray;
@property (nonatomic,strong) NSMutableArray *cengJiArray;
@property (nonatomic,strong) MCXinZhiDuReportListModel *didSelectRowAtIndexPathModel;

@property (nonatomic,assign) BOOL flag1;
@property (nonatomic,assign) BOOL flag2;
@property (nonatomic,assign) BOOL flag3;
@property (nonatomic,strong) NSDictionary *errcode;


@end

@implementation MCXinZhiDuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"制度报表";
    self.view.backgroundColor=RGB(231, 231, 231);
    [self configRequstNormalParmas];
    [self addNavRightBtn];
    [self setUpUI];
    [self setExceptionViewFrame];
}
- (NSMutableArray *)cengJiModelArray{
    if (_cengJiModelArray == nil) {
        _cengJiModelArray = [NSMutableArray array];
        
    }
    return _cengJiModelArray;
}
- (NSMutableArray *)cengJiArray{
    if (_cengJiArray == nil) {
        _cengJiArray = [NSMutableArray array];
        
    }
    return _cengJiArray;
}

-(void)loadData{
    [self.tableViewDataArray removeAllObjects];
    [self.tableView reloadData];
    [self hiddenExDataView];
    [self syncServerData];
    

}


#pragma mark --添加🔍
- (void)addNavRightBtn {
    UIButton *btn = [[UIButton alloc] init];
    [btn setBackgroundImage:[UIImage imageNamed:@"debss"] forState:UIControlStateNormal];
    self.btn =btn;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn sizeToFit];
    [btn addTarget:self action:@selector(allBtnClick:) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadReportLotteryListData];
    [self syncServerData];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.translucent = NO;
}
#pragma mark - configRequstNormalParmas
- (void)configRequstNormalParmas{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];
    self.CurrentPageIndex = 1;
    self.IsSelf = 1;
    self.isShow = 1;
    self.LotteryId = 1;
    self.UserID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    self.beginDate = [MCRecordTool getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-1];
}


- (void)syncServerData{
    [BKIndicationView showInView:self.view];
    WS(weakself);
    // 创建信号量
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    
    // 创建全局并行
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, queue, ^{
        NSLog(@"task 1");
        
        [weakself loadListData: semaphore];
        
    });
    
    dispatch_group_async(group, queue, ^{
        NSLog(@"task 2");
      
        [weakself loadSelfData: semaphore];
        
    });
    
    dispatch_group_async(group, queue, ^{
        NSLog(@"task 3");
        
        [weakself loadAllListData: semaphore];
    });
    
    dispatch_group_notify(group, queue, ^{
        
        // 三个请求对应三次信号等待
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [BKIndicationView dismiss];
            NSLog(@"task finish");
  
            if (weakself.flag1 == YES ||weakself.flag3 == YES ||weakself.flag2 == YES ) {
                [weakself showExcaptionView:weakself.errcode];
            }
            
            if (weakself.flag1 == NO &&weakself.flag2 == NO &&weakself.flag3 == NO ) {
                [weakself hiddenExDataView];
                [weakself.tableView reloadData];
            }
            
        });
    });
}


-(void)setUpUI{
    MCBreadcrumbTrailView *trailView = [[MCBreadcrumbTrailView alloc] initWithFrame:CGRectMake(0,MC_REALVALUE(0), G_SCREENWIDTH, MC_REALVALUE(30))];
    trailView.backgroundColor = RGB(249, 249, 249);
    self.trailView = trailView;
    
    NSString *fName = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
    [self.cengJiArray addObject:fName];
    MCXinZhiDuReportListModel *item = [[MCXinZhiDuReportListModel alloc] init];
    item.IsSelf =1;
    item.LotteryId = self.LotteryId;
    item.UserID = [NSString stringWithFormat:@"%d",self.UserID];
    item.CurrentPageIndex = 1;
    item.CurrentPageSize = 15;
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
    [dataFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateTemps = [dataFormatter stringFromDate:self.beginDate];
    item.Datetime = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];
    [self.cengJiModelArray addObject:item];
    trailView.dataArr = self.cengJiArray;

    trailView.selectedBreadcrumbTrailBlock = ^(NSInteger i) {
        [self.cengJiModelArray removeObjectsInRange:NSMakeRange((i + 1) , self.cengJiArray.count - i -1)];
        [self.cengJiArray removeObjectsInRange:NSMakeRange((i + 1) , self.cengJiArray.count - i -1)];
        MCXinZhiDuReportListModel *m  = [self.cengJiModelArray objectAtIndex:i];
 
        self.UserID = [m.UserID intValue];
        self.didSelectRowAtIndexPathModel = m;
        [self syncServerData];
        [self.trailView.collection reloadData];
    };
    [self.view addSubview:trailView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    UITableView *tab = [[UITableView alloc] initWithFrame:CGRectMake(0,  MC_REALVALUE(30), G_SCREENWIDTH, G_SCREENHEIGHT - MC_REALVALUE(30) - kStatusBarAndNavigationBarHeight - kTabBarHeight) style:UITableViewStylePlain];
    [self.view addSubview:tab];
    self.tableView = tab;
    __weak typeof(self) weakself = self;
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    self.tableView.mj_header = [MCRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakself syncServerData];
    }];
    tab.rowHeight = MC_REALVALUE(180);
    [tab registerClass:[MCXinZhiDuTableViewCell class] forCellReuseIdentifier:@"cell"];
    tab.delegate = self;
    tab.dataSource = self;
    tab.backgroundColor = RGB(231, 231, 231);


}

#pragma mark --发送请求
-(void)loadListData:(dispatch_semaphore_t)semaphore{
    self.tableView.mj_footer.hidden=NO;
    self.CurrentPageIndex = 1;
    __weak typeof(self) weakself = self;

    MCXinZhiDuReportListModel *listModel = [[MCXinZhiDuReportListModel alloc] init];
    self.listModel = listModel;
    listModel.IsSelf = 1;
    listModel.LotteryId = self.LotteryId;
    listModel.searchUserID = self.UserID;
    listModel.CurrentPageIndex = 1;
    listModel.CurrentPageSize = 15;
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
    [dataFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateTemps = [dataFormatter stringFromDate:self.beginDate];
    listModel.Datetime = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];
    [listModel refreashDataAndShow];
    
    
    listModel.callBackSuccessBlock = ^(id manager) {
        dispatch_semaphore_signal(semaphore);
        weakself.flag1 = NO;
        [weakself tableViewEndRefreshing];
        
        weakself.tableViewDataArray = [MCXinZhiDuReportListModel mj_objectArrayWithKeyValuesArray:manager[@"SysMgrList"]];
        if (weakself.tableViewDataArray.count==[manager[@"DataCount"] integerValue]) {
            weakself.tableView.mj_footer.hidden=YES;
        }

    };
    
    listModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        dispatch_semaphore_signal(semaphore);
        [weakself tableViewEndRefreshing];
        [weakself showExcaptionView:errorCode];
        weakself.errcode = errorCode;
         weakself.flag1 = YES;
    };
    
}

#pragma mark --发送请求
-(void)loadSelfData:(dispatch_semaphore_t)semaphore{
    self.tableView.mj_footer.hidden=NO;
    self.CurrentPageIndex = 1;
    __weak typeof(self) weakself = self;
        MCXinZhiDuReportListModel *listModel = [[MCXinZhiDuReportListModel alloc] init];

    self.listSelfModel = listModel;

    listModel.IsSelf = 0;
    listModel.LotteryId = self.LotteryId;
    listModel.searchUserID = self.UserID;
    listModel.CurrentPageIndex = 1;
    listModel.CurrentPageSize = 15;
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
    [dataFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateTemps = [dataFormatter stringFromDate:self.beginDate];
    listModel.Datetime = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];
    [listModel refreashDataAndShow];
    
    
    listModel.callBackSuccessBlock = ^(id manager) {
        dispatch_semaphore_signal(semaphore);
        weakself.flag2 = NO;
        [weakself tableViewEndRefreshing];
        
        if (weakself.tableViewDataArray.count==[manager[@"DataCount"] integerValue]) {
            weakself.tableView.mj_footer.hidden=YES;
        }

            weakself.tableViewSelfDataArray = [MCXinZhiDuReportListModel mj_objectArrayWithKeyValuesArray:manager[@"SysMgrList"]];

    };
    
    listModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        dispatch_semaphore_signal(semaphore);
        [weakself tableViewEndRefreshing];
        weakself.flag2 = YES;
        [weakself showExcaptionView:errorCode];
    };
    
}

- (void)loadMoreData{
    
    self.tableView.mj_footer.hidden=NO;
    self.listModel.CurrentPageIndex = ++self.CurrentPageIndex;
    __weak typeof(self) weakSelf = self;
    self.listModel.callBackSuccessBlock = ^(id manager) {
        [weakSelf tableViewEndRefreshing];
        NSArray *arr = [MCXinZhiDuReportListModel mj_objectArrayWithKeyValuesArray:manager[@"SysMgrList"]];

        [weakSelf.tableViewDataArray addObjectsFromArray:arr];
        [weakSelf.tableView reloadData];
        [weakSelf tableViewEndRefreshing];
        if (weakSelf.tableViewDataArray.count==[manager[@"DataCount"] integerValue]) {
            weakSelf.tableView.mj_footer.hidden=YES;
        }
    };

    self.listModel.callBackFailedBlock = ^(id manager, NSDictionary *errorCode) {
        [weakSelf tableViewEndRefreshing];
    };
    [BKIndicationView showInView:self.view];
    [self.listModel refreashDataAndShow];
}



- (void)loadReportLotteryListData{
    __weak typeof(self) weakself = self;
    [self.catergyDataArray removeAllObjects];
    MCXinZhiDuReportLotteryModel *reportSelfModel = [[MCXinZhiDuReportLotteryModel alloc] init];
    reportSelfModel.isShow = self.isShow;
    self.lotteryModel = reportSelfModel;
    [reportSelfModel refreashDataAndShow];
    reportSelfModel.callBackSuccessBlock = ^(id manager) {
       
       
        [weakself tableViewEndRefreshing];
        
        weakself.catergyDataArray = [MCXinZhiDuReportLotteryModel mj_objectArrayWithKeyValuesArray:manager];
        if (weakself.catergyDataArray.count > 0) {
            MCXinZhiDuReportLotteryModel *model = weakself.catergyDataArray[0];
            self.popView.statusLabDetail.text =model.WebName;
        }
       
    };

  
}

- (void)loadAllListData:(dispatch_semaphore_t)semaphore{
    __weak typeof(self) weakself = self;
    [self.tableViewAllDataArray removeAllObjects];
    MCXinZhiDuReportTotalModel *totalModel = [[MCXinZhiDuReportTotalModel alloc] init];
    totalModel.LotteryId = self.LotteryId;
    totalModel.UserID = [NSString stringWithFormat:@"%d",self.UserID];
    self.totalModel = totalModel;
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
    [dataFormatter setDateFormat:@"yyyy/MM/dd"];
    NSString *dateTemps = [dataFormatter stringFromDate:self.beginDate];
    totalModel.Datetime = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];

    [totalModel refreashDataAndShow];
    
    totalModel.callBackSuccessBlock = ^(id manager) {
        dispatch_semaphore_signal(semaphore);
        weakself.flag3 = NO;
        [weakself tableViewEndRefreshing];
       
        MCXinZhiDuReportTotalModel *model= [MCXinZhiDuReportTotalModel mj_objectWithKeyValues:manager];
        if (model != nil) {
            [weakself.tableViewAllDataArray addObject:model];
        }

    };
    totalModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSDictionary *errorCode) {
        dispatch_semaphore_signal(semaphore);
        [weakself tableViewEndRefreshing];
        [weakself showExcaptionView:errorCode];
        weakself.flag3 = YES;
    };
}



- (void)tableViewEndRefreshing{
    [self.tableView.mj_footer endRefreshing];
    [self.tableView.mj_header endRefreshing];


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (self.tableViewAllDataArray.count>0&&self.tableViewSelfDataArray.count>0) {
        return self.tableViewDataArray.count + 2;
    }
    return 0;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MCXinZhiDuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
 
    if (indexPath.row >= 2) {
        cell.isSelf = 0;
        if (self.tableViewDataArray.count>0) {
            if (self.tableViewDataArray.count >= indexPath.row -2) {
                 cell.dataSource = self.tableViewDataArray[indexPath.row - 2];
            }
           
        }
      
    } else if (indexPath.row == 1){
        
        if (self.tableViewSelfDataArray.count>0) {
            cell.isSelf = 1;
            cell.dataSource = self.tableViewSelfDataArray[0];
            cell.didSelectRowAtIndexPathModel = self.didSelectRowAtIndexPathModel;
        }
    }else if (indexPath.row == 0){
        cell.isSelf = 0;
        if (self.tableViewAllDataArray.count>0) {
            cell.dataSource = self.tableViewAllDataArray[0];
            cell.didSelectRowAtIndexPathModel = self.didSelectRowAtIndexPathModel;
        }
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.tableViewDataArray.count==0) {
        return;
    }
    if (indexPath.row>=2) {
        MCXinZhiDuReportListModel *model = self.tableViewDataArray[indexPath.row -2];
        self.didSelectRowAtIndexPathModel = model;
            if ([model.ChildNum intValue] > 0) {
                self.UserID = [model.UserID intValue];
                [self.cengJiArray addObject:model.UserName];
                [self.cengJiModelArray addObject:model];
                [self.trailView.collection reloadData];
                [self syncServerData];
            }
        
}
   

}



- (void)allBtnClick:(UIButton *)btn{
    if (_isShowPopView) {
        
        _isShowPopView=NO;
        [self.popView hidePopView];
        
    }else{
        [self.view bringSubviewToFront:self.popView];
        _isShowPopView=YES;
        typeof(self) weakself = self;
        self.popView.searchBtnBlock = ^(NSString *str) {
            _isShowPopView=NO;
            
            NSString *fName = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"];
            weakself.cengJiArray =[NSMutableArray arrayWithArray:@[fName]] ;
           
            MCXinZhiDuReportListModel *item = [[MCXinZhiDuReportListModel alloc] init];
            item.IsSelf =1;
            item.LotteryId = weakself.LotteryId;
            item.UserID = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
            item.CurrentPageIndex = 1;
            item.CurrentPageSize = 15;
            NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
            [dataFormatter setDateFormat:@"yyyy/MM/dd"];
            NSString *dateTemps = [dataFormatter stringFromDate:weakself.beginDate];
            item.Datetime = [NSString stringWithFormat:@"%@ 00:00:00",dateTemps];
            weakself.didSelectRowAtIndexPathModel = item;
            weakself.trailView.dataArr = weakself.cengJiArray;
            weakself.cengJiModelArray =[NSMutableArray arrayWithArray:@[item]] ;
            
            [weakself.trailView.collection reloadData];
            [weakself.viewPop hiden];
            weakself.UserID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
           
            [weakself  syncServerData];
           
            
        };
        
        self.popView.statusBlock = ^{

            NSMutableArray *arrM = [NSMutableArray array];
            for (MCXinZhiDuReportLotteryModel *model in weakself.catergyDataArray) {
                [arrM addObject:model.WebName];
            }

            weakself.viewPop.dataArray = arrM;

            [weakself.viewPop show];
            weakself.viewPop.cellDidSelectedTop = ^(NSInteger i) {
                [weakself.viewPop hiden];
                weakself.popView.statusLabDetail.text = weakself.viewPop.dataArray[i];

                weakself.LotteryId = [(MCXinZhiDuReportLotteryModel *)weakself.catergyDataArray[i] Id];
            };
        };
        [weakself datePickerCallBack];
        [self.popView showPopView];
    }
}

- (void)datePickerCallBack{
    typeof(self) weakself = self;
    self.popView.startDateBlock = ^{
        weakself.datePicker.cancelBlock = ^{
            [UIView animateWithDuration:0.25 animations:^{
                [weakself.datePicker removeFromSuperview];
            }];
        };
        weakself.datePicker.sureBlock = ^(NSString *selectDateStr) {
            weakself.popView.startDateLabDetail.text = selectDateStr;
            NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
            [dataFormatter setDateFormat:@"yyyy-MM-dd"];
            weakself.beginDate = [dataFormatter dateFromString:selectDateStr];
            [UIView animateWithDuration:0.25 animations:^{
                [weakself.datePicker removeFromSuperview];
                
            }];
        };
        
    };
    
}

- (void)tap{
    self.isShowPopView=NO;
    self.popView.hidden = YES;
    [self.viewPop hiden];
}

#pragma mark  getter and setter

- (NSMutableArray *)tableViewDataArray{
    
    if (_tableViewDataArray == nil) {
        _tableViewDataArray = [NSMutableArray array];
    }
    return _tableViewDataArray;
}
- (NSMutableArray *)catergyDataArray{
    
    if (_catergyDataArray == nil) {
        _catergyDataArray = [NSMutableArray array];
    }
    return _catergyDataArray;
}
- (NSMutableArray *)tableViewSelfDataArray{
    
    if (_tableViewSelfDataArray == nil) {
        _tableViewSelfDataArray = [NSMutableArray array];
    }
    return _tableViewSelfDataArray;
}
- (NSMutableArray *)tableViewAllDataArray{
    
    if (_tableViewAllDataArray == nil) {
        _tableViewAllDataArray = [NSMutableArray array];
    }
    return _tableViewAllDataArray;
}

- (DatePickerView *)datePicker{
    
    if (_datePicker == nil) {
        DatePickerView *datePicker =[[[NSBundle mainBundle] loadNibNamed:@"DatePickerView" owner:self options:0] lastObject];
        datePicker.minDate = [MCRecordTool getLaterDateFromDate:[NSDate date] withYear:0 month:-3 day:1];
        datePicker.maxDate = [MCRecordTool getLaterDateFromDate:[NSDate date] withYear:0 month:0 day:-1];
        datePicker.frame =CGRectMake(0, self.view.frame.size.height  - 200 -kTabBarHeight , self.view.frame.size.width, 200);
        datePicker.Datetitle =@"日期选择";
        [self.popView addSubview:datePicker];
        _datePicker = datePicker;
    }
    return _datePicker;
}

- (MCXinZhiDuPopView *)popView{
    
    if (_popView == nil) {
        MCXinZhiDuPopView * popView = [[MCXinZhiDuPopView alloc] init];
        [self.view addSubview:popView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
        [popView addGestureRecognizer:tap];
        _popView = popView;
    }
    
    return _popView;
}

- (MCMMIputView *)viewPop{
    if (_viewPop == nil) {
        
        MCMMIputView *viewStatus = [[MCMMIputView alloc] init];
        [self.navigationController.view addSubview:viewStatus];
        _viewPop = viewStatus;
    }
    return _viewPop;
}




- (void)setExceptionViewFrame{
    CGRect rect = CGRectMake(MC_REALVALUE(13), MC_REALVALUE(13)  + MC_REALVALUE(30), G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT-MC_REALVALUE(26)  -kTabBarHeight - MC_REALVALUE(40));
    self.noDataWin.frame = rect;
    self.errNetWin.frame = rect;
    self.errDataWin.frame = rect;
}

@end




